/***************************************************************************
 *   Copyright (C) 2005 by xihe   *
 *   xihels@163.com                                                        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef _RECEIVE_IM_HEADER_H_
#define _RECEIVE_IM_HEADER_H_

#include "Packet.h"


/**
 * 接收到的消息的头部格式封装类
 *
 */

class ReceiveIMHeader {
    public:
	ReceiveIMHeader();
	~ReceiveIMHeader();
	int getBody(const uint8_t* buf, int len);

	uint32_t getSender() const	    { return sender; }
	uint32_t getReceiver() const	    { return receiver; }
	uint32_t getServerSequence() const  { return serverSequence; }
	uint32_t getSenderIp() const	    { return senderIp; }
	uint16_t getSenderPort() const	    { return senderPort; }
	uint16_t getMessageSource() const   { return messageSource; }

    private:
	uint32_t sender;	// 发送者QQ号
	uint32_t receiver;	// 接收者QQ号
	uint32_t serverSequence;// 包序号，这个序号似乎和我们发的包里面的序号不同.
	// 可能这个序号是服务器端生成的一个总的消息序号
	uint32_t senderIp;	    // 发送者ip, 如果是服务器转发的，那么ip就是服务器ip
	uint16_t senderPort;    // 发送者端口，如果是服务器转发的，那么就是服务器的端口
	uint16_t messageSource; // 消息来源, 是好友发的，还是陌生人发的，还是系统消息等等
};

/**
 * 普通消息的头部，普通消息是指从好友或者陌生人那里来的消息。什么不是普通消息？比如系统消息
 * 这个头部跟在ReceiveIMHeader之后
 */

class  NormalIMHeader {
    public:
	NormalIMHeader();
	~NormalIMHeader();
	int getBody(const uint8_t* buf, int len);

	uint32_t getSender() const	    { return sender; }
	uint32_t getReceiver() const	    { return receiver; }
	uint32_t getSendTime() const	    { return sendTime; }
	uint16_t getSenderVersion() const   { return senderVersion; }
	uint16_t getImSequence() const	    { return imSequence; }
	uint8_t	 getSenderFace() const	    { return senderFace; }
	uint8_t  getMessageType() const	    { return messageType; }
	const uint8_t* getFileSessionKey() const { return fileSessionKey; }

    private:
	uint8_t  fileSessionKey[QQ_KEY_LENGTH];	// md5处理的发送方的uid和session key，
	// 用来在传送文件时加密一些消息

	uint32_t sender;		// 发送者QQ号
	uint32_t receiver;		// 接收者QQ号
	uint32_t sendTime;		// 发送时间
	uint16_t senderVersion;	// 发送者的QQ版本
	uint16_t imSequence;	// 消息序号
	uint16_t messageType;	// 普通消息类型，比如是文本消息还是其他什么消息
	uint8_t  senderFace;	// 发送者头像

};

#endif // _RECEIVE_IM_HEADER_H_

